package com.apes.exception;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * @BelongsProject: apes-server
 * @BelongsPackage: com.apes.exception
 * @ClassName: MessageBinding
 * @Author: pyb
 * @CreateTime: 2020-05-19 17:31
 * @Description: 异常主题与订阅者绑定表
 * @Version: 1.0
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = MessageBinding.CONST_TABLE_NAME)
public class MessageBinding extends BaseModel {
    public final static String CONST_TABLE_NAME = "message_binding";
    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "消息绑定主题")
    private String id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "message_topic_id", referencedColumnName = "id")
    @Comment("消息订阅主题")
    private MessageTopic messageTopic;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "message_subscriber", referencedColumnName = "id")
    @Comment("消息订阅者")
    private MessageSubscriber messageSubscriber;
}
